﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace SharpDownloadSDK
{
    public class FileUtilities
    {
        public static String ValidatePath(String path)
        {
            StringBuilder str = new StringBuilder(path);
            str.Replace('?', 'A');
            str.Replace('\\', 'A');
            str.Replace('/', 'A');
            str.Replace(':', 'A');
            str.Replace('*', 'A');
            str.Replace('"', 'A');
            str.Replace('<', 'A');
            str.Replace('>', 'A');
            str.Replace('|', 'A');
            return path.ToString();
        }

        public static void ValidateDirectory(String directory)
        {
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
        }

        public static bool ValidateFile(String path)
        {
            path = ValidatePath(path);
            if (File.Exists(path))
                return true;
            String saveDirectory = path.Substring(0, path.LastIndexOf('\\') + 1);
            ValidateDirectory(saveDirectory);

            return false;
        }

    }
}
